package com.arron.algorithm.leetcodetop100;


import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 两数之和 IV - 输入二叉搜索树
 */
public class TwoNumsSumTree {


    public boolean findTarget(TreeNode root, int k) {

        Set<Integer> set = new HashSet<>();

        return printTree(root, set, k);

    }


    public static boolean printTree(TreeNode root, Set<Integer> set, int k) {


        if (root == null) {
            return false;
        }

        if (set.contains(k - root.val)) {
            return true;
        }

        set.add(root.val);

        return printTree(root.left, set, k) || printTree(root.right, set, k);

    }


}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
